package com.demo;

import com.demo.register.MyRegister;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Import;

import java.sql.*;

@SpringBootApplication
//@MapperScan("com.demo.dao")
@Import(MyRegister.class)
public class SimpleMybatisMain {

    public static void main(String[] args) {
        SpringApplication.run(SimpleMybatisMain.class, args);
    }

    public static void test() throws ClassNotFoundException, SQLException {

        //1, 注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

        //2, 获取连接
        Connection con = DriverManager.getConnection(
                "jdbc:mysql://localhost:3307/auth?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true&allowMultiQueries=true&allowPublicKeyRetrieval=true",
                "root",
                "1234");

        //3, 定义 sql 语句
        String sql = "select * from pro1 where e_id = ?";

        //4，获取执行 sql 对象
        PreparedStatement preparedStatement = con.prepareStatement(sql);
        preparedStatement.setInt(1, 1);

        //5，执行 sql
        preparedStatement.execute();
        ResultSet resultSet = preparedStatement.getResultSet();

        //6，解析结果
        while( resultSet.next() ){
            System.out.print("id:" + resultSet.getString("name"));
            System.out.print("name:" + resultSet.getString("value"));
            System.out.print("type:" + resultSet.getString("e_id"));
            System.out.println();
        }
    }
}
